<!-- 新建资源库 -->
<template>
  <div>
    <mk-button :type="0"
               icon="el-icon-plus"
               @click="show">新建{{config.GlobalMap.RESOURCE[rstype]}}</mk-button>

    <mk-button :type="0"
               v-if="rstype !== 'EFECT'"
               @click="configFolder">管理文件夹</mk-button>

    <mk-upload v-if="rstype === 'VOICE'"
               multiple
               style="width:200px;display:inline-block !important"
               :type="rstype"
               :choose="false"
               :value-model="false"
               @success="reload"
               list-type="text">
      <mk-button :type="0"
                 icon="el-icon-upload">快速上传</mk-button>
    </mk-upload>

    <cmResource-folder-list :rstype="rstype"
                            v-if="folderPage.isshow"
                            @close="folderClose"></cmResource-folder-list>
    <cmResource-form v-if="visible"
                     @close="close"
                     :rstype="rstype"
                     :is-add="true"
                     :title="`新建${config.GlobalMap.RESOURCE[rstype]}`"
                     btn-name="保存" />
  </div>
</template>
<script>
import { MkBase } from 'element-ui'
import CmResourceForm from './form'
import CmResourceFolderList from '@/views/cm-resource-folder/list'
import MkUpload from 'sbin/upload'
export default {
  name: 'add-button',
  mixins: [MkBase],
  components: {
    CmResourceForm,
    CmResourceFolderList,
    MkUpload
  },
  props: {
    rstype: String
  },
  data () {
    return {
      visible: false,
      folderPage: {
        isshow: false
      }
    }
  },
  methods: {
    show () {
      this.visible = true
    },
    /**
     * 关闭对话框时触发
     * 根据弹框是否需要重载页面而反馈到列表
     */
    close (reload) {
      this.visible = false
      if (reload === true) {
        this.$emit('reload')
      }
    },
    reload () {
      this.$emit('reload')
    },
    configFolder () {
      this.folderPage.isshow = true
    },
    folderClose (reolad) {
      this.folderPage.isshow = false
    }
  }
}
</script>
